<?php
/********************************************************************
Product		: Flexicontact
Date		: 3 January 2014
Copyright	: Les Arbres Design 2009-2014
Contact		: http://www.lesarbresdesign.info
Licence		: GNU General Public License
*********************************************************************/
defined('_JEXEC') or die('Restricted Access');

class FlexicontactViewContact extends JViewLegacy
{

//---------------------------------------------------------------------------------------------------------
// display the contact form
//
function display($tpl = null)
{
// get the menu item parameters

	$app = JFactory::getApplication('site');
	$menu_params =  $app->getParams();

	if (isset($menu_params->pageclass_sfx))
		echo "\n".'<div class="flexicontact'.$menu_params->pageclass_sfx.'">';
	else
		echo "\n".'<div class=" container flexicontact">';


	
	echo "<div class='ouvidoria'>";

		echo "\n<h3>Ouvidoria - Solicitação de Informação Pública</h3>";
	
echo '<div class="content">';
			echo '<h4 class="title">Ouvidoria</h4>';
			
	echo "\n</div>";

	if (!empty($this->config_data->page_text))		// top text
		{
		JPluginHelper::importPlugin('content');
		$page_text = JHtml::_('content.prepare', $this->config_data->page_text);
		echo "\n".'<div>'.$page_text.'</div>';
		}
	
	
	
	if (!empty($errors))								// if validation failed
		{
		echo '<span class="fc_error">'.JText::_('COM_FLEXICONTACT_MESSAGE_NOT_SENT').'</span>';
		if (isset($errors['top']))
			echo '<br /><span class="fc_error">'.$errors['top'].'</span>';
		}
	
// start the form
	
	$uri = JFactory::getURI();
	$myuri = $uri->toString();
	echo "\n".'<form name="adminForm" action="'.JRoute::_($myuri).'" method="post" class="fc_form">';
	echo JHTML::_('form.token');
	echo '<input type="hidden" name="option" value="'.LAFC_COMPONENT.'" />';
	echo '<input type="hidden" name="task" value="send" />';
	?>
	
	
	<div class="fields">
		<label for=""><?php echo JText::_('COM_FLEXICONTACT_FROM_NAME') ; ?>:</label>
		<input type="text" class="fc_input" name="from_name" size="80" value="<?php echo $this->escape($this->post_data->from_name) ;?>" /> 
			<?php echo 	self::get_error('from_name');?>
	</div>
		
	<div class="fields">
		<label for=""><?php echo $this->config_data->field_prompt1 ; ?>:</label>
		<input type="text" class="fc_input" name="field1" size="30" value="<?php echo $this->escape($this->post_data->field1) ;?>" /> 
			<?php echo 	self::get_error('field1');?>
	</div>
	
	<div class="fields">
		<label for=""><?php echo JText::_('COM_FLEXICONTACT_FROM_ADDRESS') ; ?>:</label>
		<input type="text" class="fc_input" name="from_email" size="80" value="<?php echo $this->escape($this->post_data->from_email) ;?>" /> 
			<?php echo 	self::get_error('from_email');?>
	</div>
	<?php
	
	$arr = array('Denúncia','Elogio','Informação','Reclamação','Solicitação','Sugestão','Outros');
	
	
	?>
	<div class="fields">
		<label for=""><?php echo JText::_('COM_FLEXICONTACT_SUBJECT') ; ?>:</label>
		<select name="subject" >
			<option value=""></option>
			
			<?php
			
			foreach ( $arr as $value ) {
       			echo '<option value="'.$value.'" ' ;
       			
       			if($value == $this->escape($this->post_data->subject)) 
       				echo 'selected=true' ;
       			
				echo ' >'.$value.'</option>';
			}
			
			?>
			
		</select>	
		<?php echo 	self::get_error('subject');?>
	</div>
	<div class="fields">
		<label for=""><?php echo $this->config_data->field_prompt2 ; ?>:</label>
		<input type="radio" name="field2" value="sim">Sim
		<input type="radio" name="field2" value="não">Não
	<?php echo 	self::get_error('field2');?>
	</div>
	
	<div class="fields">
		<label for=""><?php echo $this->config_data->area_prompt ; ?>:</label>
		<?php
	
		$size = self::size($this->config_data->area_width, 'cols');
		echo '<textarea class="fc_input" name="area_data" rows="'.$this->config_data->area_height.'" '.$size.'>'.$this->escape($this->post_data->area_data).'</textarea>
			<br />'.self::get_error('area_data');
	?>
	</div>
	<?php 
	
	
	echo '<ul class="buttons">';
	echo '<li>';
	echo '<a href="javascript:void(0);" onclick="document.adminForm.submit();" ><img src="'. JUri::base() . 'templates/cmmacae/img/btnEnviar.jpg" /></a>';
	echo '</li>';
	
	echo '<li>';
	echo '<a href="javascript:void(0);" onclick="document.adminForm.reset();" ><img src="'. JUri::base() . 'templates/cmmacae/img/btnLimpar.jpg" /></a>';
	echo '</li>';
	
	
	echo '</ul>';
		
// bottom text

	if (!empty($this->config_data->bottom_text))
		{
		JPluginHelper::importPlugin('content');
		$bottom_text = JHtml::_('content.prepare', $this->config_data->bottom_text);
		echo "\n".'<div>'.$bottom_text.'</div>';
		}
		
	echo "\n</form>";

	echo "\n</div>";
	echo "\n</div>";				// class="flexicontact"
}

//---------------------------------------------------------------------------------------------------------
// Get and format an error message
//
function get_error($field_name)
{
	if (isset($this->errors[$field_name]))
		return '<span class="fc_error">'.$this->errors[$field_name].'</span>';
	else
		return '';
}

//-------------------------------------------------------------------------------
// field widths can be:
//    0 or blank => nothing at all
// just a number => html attribute size="number" or cols="number"
//          99px => style="width:99px !important;"
//          99em => style="width:99em !important;"
//           99% => style="width:99% !important;"
//
static function size($width, $attribute='size')
{
	if (empty($width))
		return '';
	if (strpos($width, 'px'))
		return ' style="width:'.$width.' !important;"';
	if (strpos($width, 'em'))
		return ' style="width:'.$width.' !important;"';
	if (strpos($width, '%'))
		return ' style="width:'.$width.' !important;"';
	return ' '.$attribute.'="'.$width.'"';
}

	
}
?>
